import { reject, resolve } from 'core-js/fn/promise'
import Vue from 'vue'
import Vuex from 'vuex'
import {LoginApi} from '../request/api'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:''
  },
  mutations: {
    SaveToken(state,payload){
      state.token=payload
    }
  },
  actions: {
    // 登录的方法
    login({state,commit},payload){
      return new Promise((resolve,reject)=>{
        LoginApi(payload).then(res=>{
          resolve(res)
          if(res.errno===0){
           commit('SaveToken',res.data.token)
           state.token=payload
           localStorage.setItem('token',res.data.token)
          }
        })
      })
     
    }
  },
  modules: {
  }
})
